<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/pages/common/taglibs.jsp" %>

<jsp:useBean id="JSONRPCBridge" scope="session" class="org.jabsorb.JSONRPCBridge" />
<jsp:useBean id="jabsorbService" scope="session" class="com.ivo.jabsorb.JabsorbService" />

<%
	JSONRPCBridge.registerObject("jabsorbService", jabsorbService);
%>
<html>
  <head>    
    <title>${tmpl.templateName }</title>
    <%@ include file="/pages/common/meta.jsp" %>
	<!-- import EXTJS -->
	<%@ include file="/pages/common/extjs.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx }/styles/ext-button.css">
	
	<link rel="stylesheet" type="text/css" href="${ctx }/ext-3.2/ux/fileuploadfield/css/fileuploadfield.css"/>
	<script type="text/javascript" src="${ctx }/ext-3.2/ux/fileuploadfield/FileUploadField.js"></script>
	<script type="text/javascript" src="${ctx }/ext-3.2/ux/SearchField.js"></script>
	
	<script type="text/javascript" src="${ctx }/pages/pdm/DocumentMultiSelectionWindow.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/DccLinkGrid.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/AttachmentGrid.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurSelectionWindow.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/BomReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/GpReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/MaReport.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/FurDetails.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/WorkFlowLog.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/AutoCreate.js"></script>
	<script type="text/javascript" src="${ctx }/pages/pdm/Log.js"></script>
	
	<!-- import JSONRPC -->
	<script type="text/javascript" src="${ctx }/scripts/jsonrpc.js"></script>
	
	<!-- import jQuery -->
	<link type="text/css" href="${ctx }/jQuery/themes/redmond/jquery-ui-1.8.1.redmond.css" rel="stylesheet" />
	<script type="text/javascript" src="${ctx }/jQuery/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.widget.js"></script>

	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.tabs.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.button.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ui.datepicker.js"></script>
	
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.center.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numeric.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.numberformatter-1.1.2.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.form-2.43.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.ux.formvalidate.js"></script>
	<script type="text/javascript" src="${ctx }/jQuery/ui/jquery.tablesorter.js"></script>
	
	<link rel="stylesheet" href="${ctx }/jQuery/css/table/blue/style.css" type="text/css" id="" media="print, projection, screen" /> 
	<link type="text/css" href="${ctx }/jQuery/demos.css" rel="stylesheet" />
	<link type="text/css" href="${ctx }/styles/pdm/tool_icon.css" rel="stylesheet" />
	
	<!-- import jquery easy UI-->
	<link rel="stylesheet" type="text/css" href="${ctx }/jQuery/easyui/themes/default/linkbutton.css">
	<link rel="stylesheet" type="text/css" href="${ctx }/jQuery/easyui/themes/icon.css">
	
	<!-- import sheet CSS -->
	<link rel="stylesheet" type="text/css" href="${ctx }/styles/pdm/sheet.css">
	
	<script type="text/javascript">
		window.basePath = "${ctx }";
		var bAuth = "${auth }";
		var divStyle = new Array("${tags[0] }", "${tags[1] }", "${tags[2] }");
		
		$(function(){						
			$.ajax({
				type: "post",
				cache: "false",
				url: "/pdm/page/autocreate.htm?tmpl_fk=${tmpl.templateId }&mast_fk=${mastIns.instanceId }",
				dataType: "json",
				contentType: "application/json; charset=utf-8",
				timeout: 20000,
				error: function(){
				    $("#evaluation_tab_1").html("<font color=red>请求失败，请重新刷新页面！</font>");
				    $("#preloader").hide();
				},
				success: function(json){
				    $("#evaluation_tab_1").html(json[0].data);
				    $("#preloader").hide();
				    
				    formValidate();
				    /*
					 *  如果没有权限，则设置按钮无效，所有控件只读
					 */
				    if(bAuth != "true")
				    {
					    $("input").attr("readonly", "true");
					    $("textarea").attr("readonly", "true");
				    }
				    /*
					 *  对敏感的双引号进行特殊处理
					 */
				    $("#basic_form :input").each(function(i){
						this.value = renderString(this.value);
					});
					/*
					 *  对表格中第一个栏位进行对齐
					 */
					$("#evaluation_tab_1 table table tr").each(function(i){
						var colSize = $(this).find("td").size();
						if(colSize>1)
						{
							var width_per = 83/(colSize-1);
							var a = $(this).find("td").first();
							if(!a){
								alert("null");
							}else{
								a.attr("style","height:22px; width:17%;");
							}
							
							$(this).find("td:not(:first)").each(function(j){
								$(this).attr("style","width:"+width_per+"%;");
							});
						}
					});
					/*
					 *  获取
					 */
					if(hasReportType("DT024")||hasReportType("DT037"))
					{
						var objectName = $("#btn_furSelection").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_furSelection").parent().prev().find("input").attr("value");
						var win = null;
						createFollowUpButton(win, objectName, objectValue, bAuth, window.basePath);
					}
					else if(hasReportType("DT025"))
					{
						var objectName = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("value");
						//var objectValue = $("#hidden_BoMParam").attr("value");
						createBoMReport("", objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT026"))
					{
						var objectName = $("#btn_dc_query").parent().next().find("input").attr("id");
						//var objectValue = $("#div_selected_material_grid").parent().parent().prev().find("input").attr("value");
						//var objectValue = $("#hidden_BoMParam").attr("value");
						createDcReport("", objectName, "", bAuth, "");
					}
					else if(hasReportType("DT027"))
					{
						var objectName = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_gp_param_grid").parent().parent().prev().find("input").attr("value");
						
						createGpReport("", objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT028"))
					{
						var objectName = $("#btn_select_fur").parent().prev().find("input").attr("id");
						var objectValue = $("#btn_select_fur").parent().prev().find("input").attr("value");
						
						var win = null;
						createFurDelay(win, objectName, objectValue, bAuth, "");
					}
					else if(hasReportType("DT036"))
					{
						var objectName = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("id");
						var objectValue = $("#div_ma_param_grid").parent().parent().prev().find("input").attr("value");
						
						createMaReport("", objectName, objectValue, bAuth, "");
					}
					//alert($("#div_selected_material_grid").parent().parent().prev().find("input").attr("value"));
				}
			});
		});
	</script>
	<script type="text/javascript">
	/********************************************************************************/	
		String.prototype.replaceAll = function(s1,s2){
	    	return this.replace(new RegExp(s1,"g"),s2);   
	  	}
		function renderString(a){
	   		a = a.replaceAll("@39;","\'");
	   		a = a.replaceAll("@34;","\"");
	   		a = a.replaceAll("@13;","\n");
	   		return a;
		}
		function renderGridStr(a){
	   		a = a.replaceAll("@39;","\'");
	   		a = a.replaceAll("@34;","\"");
	   		a = a.replaceAll("@13;","  ");
	   		return a;
		}
	/********************************************************************************/
		function bAuthedReadDccDoc(docNumber,docStatus){
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.bAuthedReadDccDoc(docNumber, "${user.employee_ID }", docStatus);
			}catch(e){
				alert(e);
			}
			return info;
		}
	/********************************************************************************/
		function bDccDocAuth(documentVersion_ID){
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.bAuthDccDoc("${user.employee_ID }", documentVersion_ID);
			}catch(e){
				alert(e);
			}
			return info;
		}
	/********************************************************************************/
		function hasReportType(data_type){
			var jsonrpc = new JSONRpcClient("/pdm/JSON-RPC");
			try{
				var info = jsonrpc.jabsorbService.hasReportType("${tmpl.templateId }", data_type);
			}catch(e){
				alert(e);
			}
			return info;
		}
	</script>
	
  </head>
  
  <body style="overflow-y:hidden">
  	<div class="navigator" id="nav">
	  	<div id="toolbar" class="tool-bar">
	  		<c:if test='${auth eq true }'>
			<a class="easyui-linkbutton l-btn" href="javascript:saveInfo('${tmpl.templateId }','${mastIns.instanceId }','false')">
				<span class="l-btn-left">
					<span class="l-btn-text icon-save" style="padding-left: 20px;">保存</span>
				</span>
			</a>
			<c:if test='${tags[1] eq false }'>
			<a class="easyui-linkbutton l-btn" href="javascript:saveInfo('${tmpl.templateId }','${mastIns.instanceId }','true')">
				<span class="l-btn-left">
					<span class="l-btn-text icon-ok" style="padding-left: 20px;">结案</span>
				</span>
			</a>
			</c:if>
			</c:if>
			<a class="easyui-linkbutton l-btn" href="javascript:window.close()">
				<span class="l-btn-left">
					<span class="l-btn-text icon-cancel" style="padding-left: 20px;">关闭</span>
				</span>
			</a>
			<!-- 
			<a class="easyui-linkbutton l-btn" href="javascript:window.location.href('ProductDevelopmentManagement.jsp')">
				<span class="l-btn-left">
					<span class="l-btn-text icon-back" style="padding-left: 20px;">Back</span>
				</span>
			</a>
			<a class="easyui-linkbutton l-btn" href="#">
				<span class="l-btn-left">
					<span class="l-btn-text icon-help" style="padding-left: 20px;">Help</span>
				</span>
			</a>
			 -->
			<a class="easyui-linkbutton l-btn" href="javascript:window.location.reload(true)">
				<span class="l-btn-left">
					<span class="l-btn-text icon-reload" style="padding-left: 20px;">刷新</span>
				</span>
			</a>
		</div>
	</div>
  	<div id="form-body" align=center class="form-body">
		<div id="form-name" align="center" style="width:92%; margin-top:3px;"><fieldset><font size="6">${fb.formName }</font></fieldset></div>
		<div id="basic-tab" style="width:92%; margin-top:3px;" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>基本资料</a></li>
			</ul>
			<div class="ui-tabs-panel ui-widget-content ui-corner-bottom">
				<table width="96%;">
					<tr>
						<td style="width:15%;"></td>
						<td style="width:29%;"></td>
						<td style="width:5%;"></td>
						<td style="width:15%;"></td>
						<td style="width:36%;"></td>
					</tr>
					<tr>
						<td align="right"><label for="projectName">专案名称:</label></td>
						<td align="left">
							<input type="text" name="projectName" id="projectName" value="${fb.projectName }" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right"><label for="deriveName">专案版本:</label></td>
						<td align="left">
							<input type="text" name="deriveName" id="deriveName" value="${fb.deriveName }" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					<tr>
						<td align="right"><label for="stage">阶段:</label></td>
						<td align="left">
							<input type="text" name="stage" id="stage" value="${fb.stage }" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right"><label for="dateCreate">申请日期:</label></td>
						<td align="left">
							<input type="text" name="dateOrder" id="dateOrder" value="${fb.dateOrder }" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
					<tr>
						<td align="right"><label for="creator">申请人员:</label></td>
						<td align="left">
							<input type="text" name="creator" id="creator" value="${fb.owner }" readonly style="width:88%" class="text ui-widget-content ui-corner-all" />
						</td>
						<td></td>
						<td align="right"><label for="creatorDept">部门名称:</label></td>
						<td align="left">
							<input type="text" name="creatorDept" id="creatorDept" value="${fb.ownerDept }" readonly style="width:70.8%" class="text ui-widget-content ui-corner-all" />
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div id="evaluation_tabs" style="width:92%" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>重要信息</a></li>
			</ul>
			<div id="evaluation_tab_1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
				<div id="preloader"><img src="${ctx }/images/pdm/preloading.gif" /></div>
			</div>
		</div>
		<c:if test='${tags[0] eq true || tags[2] eq true }'>
		<div id="conclusion-tab" style="width:92%; margin-top:3px;" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>结论(NA)</a></li>
			</ul>
			<div class="ui-tabs-panel ui-widget-content ui-corner-bottom">
				<div id="conclusion" align="left">
					<table style="width:95%">
						<tr>
							<td style="width:50px;">
								<input type="radio" id="available" name="conclusion" value="available" <c:if test='${fb.conclusion eq "available" }'>checked</c:if> />
								<label for="available">
									<c:choose>
									<c:when test='${tags[2] eq false }'>可行</c:when>
									<c:otherwise>Pass</c:otherwise>
									</c:choose>
								</label>
							</td>
							<td style="width:63px;">
								<input type="radio" id="unavailable" name="conclusion" value="unavailable" <c:if test='${fb.conclusion eq "unavailable" }'>checked</c:if> />
								<label for="unavailable">
									<c:choose>
									<c:when test='${tags[2] eq false }'>不可行</c:when>
									<c:otherwise>Fail</c:otherwise>
									</c:choose>
								</label>
							</td>
							<td style="width:110px;">
								<input type="radio" id="conditional" name="conclusion" value="conditional" <c:if test='${fb.conclusion eq "conditional" }'>checked</c:if> />
								<label for="conditional">
									<c:choose>
									<c:when test='${tags[2] eq false }'>有条件的</c:when>
									<c:otherwise>Conditional Pass</c:otherwise>
									</c:choose>
								</label>
							</td>
							<td>
								&nbsp;&nbsp;
								<input type="text" id="reason" name="reason" style="width:85%;" class="text ui-widget-content ui-corner-all" validator="type:string;maxLength:500;" value="${fb.reason }"/>
							</td>
						</tr>
					</table>
				</div>
			</div>
		</div>
		</c:if>
		<c:if test='${tags[1] eq true }'>
		<div id="dcc_link_tabs" style="width:92%" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>DCC Link</a></li>
			</ul>
			<div id="dcc_link_tab_1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" align=left style="width:98%;overflow-x:hidden;"></div>
			<script>
				var dccLink = new DccLinkGrid2({id: 'dccLinkGrid', mast_id: "${mastIns.instanceId }", auth: (bAuth === "true")});
				dccLink.render("dcc_link_tab_1");
			</script>
		</div>
		</c:if>
		<div id="attachment_tabs" style="width:92%"style="width:92%" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>Attachment Link</a></li>
			</ul>
			<div id="attachment_tab_1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" align=left style="width:98%;overflow-x:hidden;"></div>
			<script>
				var attachmentGrid = new AttachmentGrid({id: "attachmentGrid", mastInsId: "${mastIns.instanceId }", auth: (bAuth === "true")});
				attachmentGrid.render("attachment_tab_1");
			</script>
		</div>
		<c:if test='${auth eq true }'>
		<div id="logs_tabs" style="width:92%" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
			<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
				<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a>修改日志</a></li>
			</ul>
			<div id="logs_tab_1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" align=left style="width:98%;overflow-x:hidden;"></div>
			<script>
				var logGrid = new LogGridPanel({
												condition: {
													mastInsId: "${mastIns.instanceId }"
												}
											});
				logGrid.render("logs_tab_1");
			</script>
		</div>
		</c:if>
	</div>
	<div id="hidden_values">
		<input type="hidden" id="_collectDocument" name="_collectDocument" value="${fb.documents }" />
		<input type="hidden" id="mast_id" name="mast_id" value="${mastIns.instanceId }" />
		<input type="hidden" id="tmpl_id" name="tmpl_id" value="${tmpl.templateId }" />
		<input type="hidden" id="login_user" name="login_user" value="${user.employee_ID }" />
	</div>
	<script>
		/**  呈现Scroll Bar  **/
		var form_height = document.body.clientHeight - 30;
		$("#form-body").attr("style", "height:" + form_height + "px;");
		$(window).resize(function(){
			form_height = document.body.clientHeight - 30;
			$("#form-body").attr("style", "height:" + form_height + "px;");
		});
	</script>
  </body>
</html>
